﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;

namespace msBsc.SvRef
{
    public partial class CDateTime
    {
        public static int GetWeekIndex(DayOfWeek oDayOfWeek)
        {
            if (oDayOfWeek == DayOfWeek.Sunday)
            {
                return 7;
            }
            if (oDayOfWeek == DayOfWeek.Monday)
            {
                return 1;
            }
            if (oDayOfWeek == DayOfWeek.Tuesday)
            {
                return 2;
            }
            if (oDayOfWeek == DayOfWeek.Wednesday)
            {
                return 3;
            }
            if (oDayOfWeek == DayOfWeek.Thursday)
            {
                return 4;
            }
            if (oDayOfWeek == DayOfWeek.Friday)
            {
                return 5;
            }
            if (oDayOfWeek == DayOfWeek.Saturday)
            {
                return 6;
            }
            else
            {
                return -1;
            }
        }
        public static int GetWeekDay(DateTime dtNow)
        {
            return GetWeekIndex(dtNow.DayOfWeek);
        }


        /// <summary>
        /// 将“1，2，2-4，7”转换为7位数组
        /// </summary>
        /// <param name="strWeekDays"></param>
        /// <returns></returns>
        public static bool[] GetArrWeekDays(string strWeekDays)
        {
            string[] arrDays1 = strWeekDays.Split(',');
            bool[] arrWeekDayi = new bool[7];
            for (int r = 0; r < 7; r++)
            {
                arrWeekDayi[r] = false;
            }
            for (int i = 0; i < arrDays1.Length; i++)
            {
                string strDays1 = arrDays1[i];
                int iParsetem1 = -1;
                if (int.TryParse(strDays1, out iParsetem1))
                {
                    arrWeekDayi[iParsetem1 - 1] = true;
                }
                if (strDays1.IndexOf("-") != -1)
                {
                    string[] arrDays2 = strDays1.Split('-');
                    string strDays2Start = "1";
                    string strDays2End = "7";
                    if (arrDays2.Length > 0 && arrDays2[0] != string.Empty)
                        strDays2Start = arrDays2[0];
                    if (arrDays2.Length > 1 && arrDays2[1] != string.Empty)
                        strDays2End = arrDays2[1];
                    if (int.TryParse(strDays2Start, out iParsetem1) && int.TryParse(strDays2End, out iParsetem1))
                    {
                        int iStarttem1 = int.Parse(strDays2Start);
                        int iEndtem1 = int.Parse(strDays2End);
                        if (iStarttem1 <= iEndtem1 && iStarttem1 > 0)
                        {
                            for (int r = iStarttem1 - 1; r < iEndtem1; r++)
                            {
                                arrWeekDayi[r] = true;
                            }
                        }
                    }
                }
            }
            return arrWeekDayi;
        }

        public static string getDayOfWeek(string strDateTime)
        {
            string strResult = string.Empty;
            try
            {
                DayOfWeek myDayOfWeek = DateTime.Parse(strDateTime).DayOfWeek;
                switch (myDayOfWeek.ToString())
                {
                    case "Sunday":
                        strResult = "日";
                        break;
                    case "Monday":
                        strResult = "一";
                        break;
                    case "Tuesday":
                        strResult = "二";
                        break;
                    case "Wednesday":
                        strResult = "三";
                        break;
                    case "Thursday":
                        strResult = "四";
                        break;
                    case "Friday":
                        strResult = "五";
                        break;
                    case "Saturday":
                        strResult = "六";
                        break;
                }
                return strResult;
            }
            catch (Exception e)
            {
                throw e;
            }

        }

    }
}
